package utils 
{
	import com.greensock.TweenMax;
	import flash.display.DisplayObject;
	import flash.geom.ColorTransform;
	/**
	 * Color utilites
	 * ...
	 * @author SChabanov
	 */
	public final class ColorUtils 
	{
		
		public static const WHITE:uint = 0xFFFFFF;
		public static const RED:uint = 0xFF0000;
		public static const GREEN:uint = 0x00FF00;
		public static const BLUE:uint = 0x0000FF;
		
		private static var _color:ColorTransform;
		
		public function ColorUtils() 
		{
			throw new Error("constructor not needed")
		}
		/**
		 * 
		 * @param	r
		 * @param	g
		 * @param	b
		 * @return
		 */
		public static function getColor(r:int,g:int,b:int):uint
		{
			_color ||= new ColorTransform();
			_color.redOffset = r;
			_color.greenOffset = g;
			_color.blueOffset = b;
			return _color.color;
		}
		/**
		 * 
		 * @param	color
		 * @return
		 */
		public static function getRGB(color:uint):Object{

			_color ||= new ColorTransform();
			_color.color = color;
            var r:int = _color.redOffset;
		    var g:int = _color.greenOffset;
		    var b:int = _color.blueOffset;
            return {r:r, g:g, b:b};
        }
		/**
		 * 
		 * @param	d
		 * @param	color
		 * @param	alpha
		 */
		public static function changeColor(d:DisplayObject,color:uint = RED):void
		{
			var ct:ColorTransform = d.transform.colorTransform;
			ct.color = color;
			d.transform.colorTransform = ct;
		}
		
		public static function removeTint(d:DisplayObject,duration:Number):void
		{
			TweenMax.to(d,duration, {colorTransform:{tintAmount:0}});
		}
		
		public static function setTint(d:DisplayObject,color:uint,duration:Number=1,tint:Number=0.5,repeat:Boolean=false):void
		{
			var rep:int = repeat ? -1 : 0;
			TweenMax.to(d,duration, {colorTransform:{tint:color, tintAmount:tint},yoyo:repeat,repeat:rep});
		}
						
	}

}